package pl.enigmatic;

/**
 * Provides a way to apply custom logic to a binding.
 * 
 * @author reggie_7
 */
public interface ValueConverter<S, T> {

	/**
	 * Converts a value.
	 * 
	 * @param value the value produced by the binding source
	 * @return a converted value. If the method returns null, the valid null value is used.
	 */
	public T convert(S value);

	/**
	 * Converts a value.
	 * 
	 * @param value the value that is produced by the binding target
	 * @return a converted value. If the method returns null, the valid null value is used.
	 */
	public S convertBack(T value);

	public static class IdentityImpl<X> implements ValueConverter<X, X> {

		@Override
		public X convert(X value) {
			return value;
		}

		@Override
		public X convertBack(X value) {
			return value;
		}
	}
}